// pages/mine/mine-main/mine-main.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    menuItems: [
      { title: '信用分', value: '80', isActive: false },
      { title: '保证金', value: '5元', isActive: false },
      //{ title: '关注服务', value: '', isActive: false },
      { title: '智能客服', value: '', isActive: false }
    ],
    currentTab: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2  // Set to the appropriate tab index (0-3)
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  handleItemClick(e: WechatMiniprogram.TouchEvent) {
    const index = e.currentTarget.dataset.index as number;
    const menuItems = this.data.menuItems;
    const item = menuItems[index];
    switch (index) {
      case 0:
        // wx.navigateTo({
        //   url: '/pages/mine/mine-credit/mine-credit'
        // });
        break;
      case 1:
        wx.navigateTo({
          url: '/pages/mine/mine-deposit/mine-deposit'
        });
        break;
      case 2:
        wx.navigateTo({
          url: '/pages/mine/mine-mark-list/mine-mark-list'
        });
        break;
      case 3:
        // wx.navigateTo({
        //   url: '/pages/mine/mine-service/mine-service'
        // });
        break;
    }
  },

  /**
   * Handle touch start on a menu item
   */
  handleTouchStart(e: WechatMiniprogram.TouchEvent) {
    const index = e.currentTarget.dataset.index as number;
    const menuItems = this.data.menuItems;
    menuItems[index].isActive = true;
    this.setData({ menuItems });
  },

  /**
   * Handle touch end on a menu item
   */
  handleTouchEnd(e: WechatMiniprogram.TouchEvent) {
    const index = e.currentTarget.dataset.index as number;
    const menuItems = this.data.menuItems;
    
    setTimeout(() => {
      menuItems[index].isActive = false;
      this.setData({ menuItems });
    }, 150);
  }
})